package cn.gcjxsc.service.worker;

import cn.gcjxsc.entity.mall.BaseOrder;
import cn.gcjxsc.entity.mall.WaitForDoneOrderInfo;
import cn.gcjxsc.service.task.TaskOrderBusiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author pumbaa
 */
@Component
@Slf4j
public class FetchOrderWorker extends SingleWorker {

    @Autowired
    private TaskOrderBusiService service;

    @Override
    protected void doBusiness() {
        //查询已发货,超过7天未完成的订单
        List<BaseOrder> baseOrders = service.queryUndoneOrder4sending(100, 7);
        System.out.println(">>>>>>>>>>>> size:" + baseOrders.size());
        if (baseOrders.size() > 0) {
            List<WaitForDoneOrderInfo> list = new ArrayList<>();
            baseOrders.forEach(d-> list.add(service.convert(d)));
            try {
                service.save(list);
            } catch (Exception e) {
                log.error("保存待完成订单信息失败.{}", e.getMessage());
            }
            try {
                //休眠半小时
                Thread.sleep(1800000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
